package com.health.service;


import com.health.dao.EditInformationDao;
import com.health.dao.UserDao;
import com.health.pojo.Users;

import java.util.List;

public class UserService {

    UserDao userDao = new UserDao();
    EditInformationDao editInformationDao = new EditInformationDao();

    /**
     * 登录方法
     */
    public int login(String checkCode, String checkCodeForUser, Users users) {
        String loginStatus = userDao.selectByUser(users);
        if (!(checkCode.equalsIgnoreCase(checkCodeForUser))) {
            // 验证码错误
            return 2;
        } else if ("true".equals(loginStatus)) {
            // 登录成功
            return 0;
        } else if ("false".equals(loginStatus)) {
            // 用户密码错误
            return 1;
        } else if ("systemError".equals(loginStatus)) {
            // 抛异常
            return -1;
        } else if ("admin".equals(loginStatus)) {
            // 商家端登录成功
            return 3;
        } else {
            // 未知错误
            return -1;
        }
    }

    /**
     * 查询用户个人信息方法
     */
    public Users searchInformation(Users user, int id) {
        return editInformationDao.searchInformation(user, id);
    }

    /**
     * 更新用户个人信息
     */
    public Boolean sendInformation(Users user) {
        return editInformationDao.updateData(user);
    }

    public List<Users> searchUserInformation() {
        return userDao.selectUserId();
    }

    public List<Users> searchDataByCombo(int userId) {
        return userDao.selectDataById(userId);
    }

    public List<Users> searchDataByItem(int userId, int examineId, String examineDate) {
        return userDao.selectDataByCombo(userId, examineId, examineDate);
    }

}
